﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;

namespace Arbetsfornedringen
{
    public partial class Default : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            GridAds.DataSource = DAL.AdDB.GetWorkAds();
            GridAds.DataBind();
        }

        private void SaveAd(WorkAds ad)
        {
            var acc = Session["Account"] as Account;
            acc.AppliedJob.Add(ad);
            Model.GetContext().SaveChanges();
        }




        protected void GridAds_RowCommand1(object sender, GridViewCommandEventArgs e)
        {
            bool verify = e.CommandName == "AddJob";
            if (verify)
            {
                int workId = int.Parse(GridAds.Rows[int.Parse(e.CommandArgument.ToString())].Cells[0].Text);
                var item = Model.GetContext().WorkAdsSets.FirstOrDefault(w => w.WorkId == workId);
                SaveAd(item);
            }
            
        }



    }
}